package org.oos.lists;

import java.util.AbstractList;
import java.util.List;

import org.oos.OOS4Java;
import org.oos.atom.entries.OfferEntry;
import org.oos.model.Offer;
import org.oos.util.Cache;

public class OfferList extends AbstractList<Offer> {

	private transient OOS4Java oos4Java;
	private List<OfferEntry> list;
	private Cache<OfferEntry, Offer> cache;
	
	
	
	private OfferList(OOS4Java oos4Java, List<OfferEntry> list) {
		super();
		this.oos4Java = oos4Java;
		this.list = list;
	}
	
	public Cache<OfferEntry, Offer> getCache() {
		if (cache == null) {
			cache = new Cache<OfferEntry, Offer>();
		}
		return cache;
	}
	
	@Override
	public Offer get(int index) {
		OfferEntry entry = list.get(index);
		Offer result = null;
		if (getCache().containsKey(entry)) {
			result = getCache().get(entry);
		} else {
			result = new Offer(oos4Java, entry);
			getCache().put(entry, result);
		}
		return result;
	}
	
	public void setOos4Java(OOS4Java oos4Java) {
		this.oos4Java = oos4Java;
	}
	
	@Override
	public int size() {
		return list.size();
	}
	
	
	
}
